import pyecharts.options as opts
from pyecharts.charts import Tree
from DataAnalyze import YearMovies


year, movie_data = YearMovies()

# 构造类似于递归字典的数据类型
for y in year:
    movie_data[y] = [{"name": value, "children": 1} for value in movie_data[y]]
data = [{'name': y, 'children': movie_data[y]} for y in year]
data = {'name': "电影", 'children': data}

tree = (
    Tree()
    .add(
        series_name="",
        data=[data],
        pos_top="18%",
        pos_bottom="14%",
        layout="radial",
        symbol="emptyCircle",
        symbol_size=7,
    )
    .set_global_opts(
        tooltip_opts=opts.TooltipOpts(trigger="item", trigger_on="mousemove")
    )
    .render("../SourceChart/Tree.html")
)
